import { createRouter, createWebHashHistory } from 'vue-router'
import UserManage from './modules/UserManage'
import RoleList from './modules/RoleList'
import PermissionList from './modules/PermissionList'
import Articel from './modules/Articel'
import ArticleCreate from './modules/ArticleCreate'
import store from '../store'

export const privateRoutes = [
  UserManage, RoleList, PermissionList, Articel, ArticleCreate
]

console.log(privateRoutes)

export const publicRoutes = [
  {
    path: '/',
    redirect: '/profile',
    component: () => import('@/layout/index'),
    children: [
      // 个人中心
      {
        path: '/profile',
        name: 'profile',
        component: () => import('@/views/profile/index'),
        meta: {
          title: 'profile',
          icon: 'el-icon-user'
        }
      },
      // 404
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/error-page/404')
      },
      // 401
      {
        path: '/401',
        name: '401',
        component: () => import('@/views/error-page/401')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: import('@/views/login')
  }

]

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...publicRoutes]
})

/**
 *  初始化 路由
 */
export function resetRouter() {
  if (store.getters.userInfo && store.getters.userInfo.permission && store.getters.userInfo.permission.menus) {
    const menus = store.getters.userInfo.permission.menus
    menus.forEach(menu => {
      router.removeRoute(menu)
    })
  }
}

export default router
